package com.mljr.example.base;

import com.ctakit.sdk.app.BaseApplication;
import com.mljr.example.BuildConfig;
import com.mljr.example.util.AppUtils;
import com.orhanobut.logger.LogLevel;
import com.orhanobut.logger.Logger;

import java.util.LinkedHashMap;
import java.util.Map;

public class MyApplication extends BaseApplication {

    private Map<String, String> myGlobalHeaders;

    @Override
    public void onCreate() {
        super.onCreate();
        AppUtils.setInstance(this);
        //控制台打印日志配置（主要是 json 数据格式化显示）
        if (BuildConfig.DEBUG) {
            Logger.init("example")
                    .methodCount(0)
                    .hideThreadInfo()
                    .logLevel(LogLevel.FULL);
        } else {
            Logger.init("example")
                    .methodCount(0)
                    .hideThreadInfo() // default shown
                    .logLevel(LogLevel.NONE); // default LogLevel.FULL
        }

        Logger.d("启动。。。。。");

    }


    public Map<String, String> getGlobalHeaders() {
        if (myGlobalHeaders != null && !myGlobalHeaders.isEmpty()) {
            return myGlobalHeaders;
        } else {
            Map<String, String> headers = super.getGlobalHeaders();
            if (headers == null) {
                headers = new LinkedHashMap<>();
            }
            headers.put("User-Agent", Global.getUserAgentClient());
            myGlobalHeaders = headers;
        }
        return myGlobalHeaders;
    }

}
